from django.db import models

# Create your models here.

class StudentModel(models.Model):
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=32,verbose_name='姓名')
    age = models.SmallIntegerField(verbose_name='年龄')
    class_mate_f = models.ForeignKey(to='ClassMateModel',on_delete=models.SET_NULL,null=True,
                                     related_name='students',related_query_name='students',db_constraint=False)

class ClassMateModel(models.Model):
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=64,verbose_name='班级名')

class ClassMateDetail(models.Model):
    id = models.AutoField(primary_key=True)
    address = models.CharField(max_length=32,verbose_name='地址')
    class_mate_f = models.ForeignKey(to='ClassMateModel',on_delete=models.CASCADE,null=True,
                                     related_name='detail',related_query_name='detail',db_constraint=False)

class TeacherModel(models.Model):
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=32,verbose_name='姓名')
    age = models.SmallIntegerField(verbose_name='年龄')
    phone = models.CharField(max_length=13,verbose_name='手机号码')
    class_mate_f = models.ManyToManyField(to='ClassMateModel',null=True,
                                          related_name='teachers',related_query_name='teachers',db_constraint=False)

#通过其他三张表的related_name 后，ClassMateModel就多了三个虚拟字段：students，teachers，classmatedetail